<template>
  <div class="contaiter">
    <el-form
      ref="courses"
      :model="courses"
      label-position="left"
      label-width="150px"
      :rules="rules"
    >
      <el-form-item label="课程名称" required prop="coursesName">
        <span slot="label" class="left-label">
          <span calss="cn-label">课程名称</span><br />
          <span class="en-label">Course Name</span>
        </span>
        <el-input
          v-model="courses.coursesName"
          placeholder="请输入课程名称"
          style="width: 50%"
        />
      </el-form-item>
      <el-form-item label="完成时间" required prop="time">
        <span slot="label" class="left-label">
          <span calss="cn-label">完成时间</span><br />
          <span class="en-label">Completion time</span>
        </span>
        <el-date-picker
          v-model="courses.time"
          type="date"
          format="yyyy-MM-dd"
          value-format="yyyy-MM-dd"
          placeholder="选择完成时间"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item label=" ">
        <el-button @click="cancel">取消</el-button>
        <el-button type="primary" @click="submitForm('courses')"
          >确定</el-button
        >
        <el-popconfirm
          title="确定删除吗？"
          class="delete-icon"
          @confirm="deleteConfirm"
          v-if="showDel"
        >
          <i class="delete-icon" slot="reference"></i>
        </el-popconfirm>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  components: {},
  props: {},
  data() {
    return {
      courses: {
        coursesName: "", //证书名称
        time: "", //获得时间
      },
      rules: {
        coursesName: [
          { required: true, message: "请输入课程名称", trigger: "blur" },
        ],
        time: [
          { required: true, message: "请选择完成时间", trigger: "change" },
        ],
      },
      index: null,
      showDel: false,
    };
  },
  methods: {
    businessAreaChange(e) {
      console.log(e);
    },
    handleCityChange(e) {
      console.log(e);
    },
    cancel() {
      this.courses = {
        coursesName: "", //证书名称
        time: "", //获得时间
      };
      this.showDel = false;
      this.index = null;
      this.$parent.$parent.$parent.closeFun("courses");
      this.$nextTick(() => {
        this.$refs["courses"].clearValidate();
      });
    },
    deleteConfirm() {
      this.$parent.$parent.$parent.deleteFun("courses", this.index);
      this.cancel();
    },
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          let data = JSON.parse(JSON.stringify(this.courses));
          this.$parent.$parent.$parent.upDate("courses", data, this.index);
          this.cancel();
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    init(data, index) {
      data = JSON.parse(JSON.stringify(data));
      this.courses = data;
      this.index = index;
      this.showDel = true;
    },
  },
  created() {},
  mounted() {},
};
</script>

<style lang="less" scoped>
.delete-icon {
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  cursor: pointer;
  display: inline-block;
  width: 32px;
  height: 32px;
  background: url("../../../assets/images/delete_icon.png") no-repeat center
    center / cover;
}
</style>
